﻿@using SCMS.Resources
@model SCMS.UI.Models.ViewPOs

<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            @Resources_frank.Global_String_PO: @Model.POEntiy.RefNumber</h3>
    </div>
    @if (Model.CanEdit)
    {
        string editUrl = "";
        if (Model.POEntiy.TenderAnalysi == null)
        {
            editUrl = "EditSingleQ/" + Model.POEntiy.Id;
        }
        else
        {
            editUrl = "EditPO/" + Model.POEntiy.Id;
        }
        <center>
            @Ajax.ActionLink(Resources_frank.PurchaseOrder_String_EditPO, "Index", new { id = "EditPO" }, new AjaxOptions
            {
                UpdateTargetId = "PODiv",
                LoadingElementId = "loading",
                Url = Url.Action(editUrl),
                OnSuccess = "clearPOItemNumbers"
            }) |
            @Ajax.ActionLink(Resources_frank.PurchaseOrder_ViewPurchaseOrders_DeletePO, "Index", new { id = "DeletePO" }, new AjaxOptions
            {
                UpdateTargetId = "PODiv",
                LoadingElementId = "loading",
                Url = Url.Action("DeletePO/" + Model.POEntiy.Id),
                Confirm = "Delete '" + Model.POEntiy.RefNumber + "'?",
                OnSuccess = "usermsg('" + Resources_frank.PurchaseOrder_String_PODeleted + "');if (document.getElementById('table') != null) {initSorter();sorter.size(50);}"
            })
        </center>
    }
    else if(Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.POEntiy.IsReviewed == true && Model.POEntiy.IsAuthorized == false && !Model.POEntiy.IsRejected)
        {
            linkText = Resources_frank.PurchaseOrder_String_AuthorizePurchaseOrder;
            actionName = "LoadPurchaseOrderForAuth";
        }
        else if (Model.POEntiy.IsSubmitted && Model.POEntiy.IsReviewed == false && !Model.POEntiy.IsRejected)
        {
            linkText = Resources_frank.PurchaseOrder_String_ReviewPurchaseOrder;
            actionName = "LoadPurchaseOrder";
        }
        if(linkText != null)
        {
            <center>
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "" }, new AjaxOptions
           {
               OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.POEntiy.RefNumber + "')",
               UpdateTargetId = "popup-page",
               LoadingElementId = "popup-loading",
               Url = Url.Action(actionName + "/" + Model.POEntiy.Id, "RequestReview"),
               OnSuccess = "CenterPopupPO"
           }) 
            </center>
        }
    }
    else
    {
        <br />
    }
    @{string Tavalue = Resources_frank.PurchaseOrder_String_SingleQuote;}
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center">
                @Resources_frank.Global_String_Date
            </th>
            <th align="center">
                @Resources_frank.Global_String_PurchaseOrderNo
            </th>
            <th align="center">
                @Resources_frank.Global_String_TenderAnalyaisNo
            </th>
            <th align="center">
                @Resources_frank.Global_String_OrderRequestNo
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.POEntiy.PODate.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.POEntiy.RefNumber
            </td>
            <td align="center">
                @if (Model.POEntiy.TenderAnalysi == null)
                { @Tavalue}
                else
                {@Model.POEntiy.TenderAnalysi.RefNumber }
            </td>
            <td align="center">
                @Model.ORNumber
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources_frank.Global_String_PaymentTerms
            </th>
            <th align="center">
                @Resources_frank.PurchaseOrder_String_QuotationRef
            </th>
            <th align="center">
                @Resources_frank.Global_String_ShippingTerms
            </th>
            <th align="center">
                @Resources_frank.Global_String_Currency
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.paymentTerm
            </td>
            <td align="center">
                @Model.POEntiy.QuotationRef
            </td>
            <td align="center">
                @Model.shippingTerm
            </td>
            <td align="center">
                @ViewBag.Currency
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources_frank.PurchaseOrder_EditPO_ToSupplier
            </th>
            <th align="center">
                @Resources_frank.Global_String_DeliveryAddress
            </th>
            <th align="center">
                @Resources_frank.GoodsReceivedNote_LoadGRNVerifyItems_DeliveryDate
            </th>
            <th align="center">
                @Resources_frank.Global_String_DRCRemarks
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.supplier
            </td>
            <td align="center">
                @Model.POEntiy.Location.Name
            </td>
            <td align="center">
                @Model.POEntiy.LatestDeliveryDate.ToString("dd/MM/yyyy")
            </td>
            <td>
                @Model.POEntiy.Remarks
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center">
                @Resources_frank.Global_String_No
            </th>
            <th align="center">
                @Resources_morgan.Global_String_ItemName
            </th>
            <th align="center">
                @Resources_morgan.Global_String_UnitOfMeasure
            </th>
            <th align="center">
                @Resources_morgan.Global_String_Quantity
            </th>
            <th align="center">
                @Resources_frank.PurchaseOrder_AddPOItems_UnitPrice
            </th>
            <th align="center">
                @Resources_frank.PurchaseOrder_AddPOItems_TotalPrice
            </th>
            <th align="center">
                @Resources_frank.Budget_CategoryList_ProjectNo
            </th>
            <th align="center">
                @Resources_frank.Budget_CreateSubLine_LineNumber
            </th>
            <th align="center">
                @Resources_morgan.Global_String_Remarks
            </th>
        </tr>
        @{int num = 0;}
        @for (int i = 0; i < Model.POItems.Count; i++)
        {
            num = num + 1;
            <tr class="gridodd">
                <td style="width: 5%; text-align: right;">
                    @num
                </td>
                <td style="width: 20%;">
                    @if (Model.POItems[i].EntityPOItem.OrderRequestItem != null)
                    {
                        @Model.POItems[i].EntityPOItem.OrderRequestItem.Item.Name
                    }
                    else
                    { 
                        @Html.Raw(Resources_frank.Global_String_TransportCost)
                    }
                </td>
                <td style="width: 10%; text-align: center;">
                    @Model.POItems[i].Unitmessue
                </td>
                <td style="width: 10%; text-align: center;">
                    @Model.POItems[i].Qunatity
                </td>
                <td style="width: 10%; text-align: right;">
                    @Model.POItems[i].EntityPOItem.UnitPrice.ToString("#,##0.00")
                </td>
                <td style="width: 10%; text-align: right;">
                    @Model.POItems[i].EntityPOItem.TotalPrice.ToString("#,##0.00")
                </td>
                <td style="width: 10%; text-align: center;">
                    @Model.POItems[i].ProjectNo
                </td>
                <td style="width: 10%; text-align: center;">
                    @Model.POItems[i].BudgetLine
                </td>
                <td style="width: 15%; text-align: left;">
                    @Model.POItems[i].EntityPOItem.Remarks
                </td>
            </tr>
        }
        <tr>
            <td colspan="3" class="gridheader" align="right">
                @Resources_frank.Global_String_CurrencyOfPurchaseOrder:&nbsp;
            </td>
            <td align="center">
                @ViewBag.Currency
            </td>
            <td class="gridheader" align="right">
                @Resources_frank.Global_String_Total:&nbsp;
            </td>
            <td align="right">
                @if (Model.TotalAmount != null)
                {
                    <b>@Model.TotalAmount.Value.ToString("#,##0.00")</b>
                }
            </td>
            <td colspan="3" class="gridheader">
                &nbsp;@Resources_frank.Global_String_POValue
            </td>
        </tr>
        <tr>
            <td colspan="3" class="gridheader" align="right">
                @Resources_frank.Global_String_MasterBudgetCurrency:&nbsp;
            </td>
            <td align="center">
                @ViewBag.MBCurrency
            </td>
            <td class="gridheader" align="right">
                @Resources_frank.Global_String_Total:&nbsp;
            </td>
            <td align="right">
                @if (Model.MBValue != null)
                {
                    <b>@Model.MBValue.Value.ToString("#,##0.00")</b>
                }
            </td>
            <td colspan="3" class="gridheader">
                &nbsp;@Resources_frank.Global_String_POValue
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr>
            <th colspan="4">
                @Resources_frank.PurchaseOrder_LoadOtherPODetails_DocumentationRequired
            </th>
        </tr>
        <tr>
            <td width="25%">
                @Html.CheckBoxFor(p => p.POEntiy.ProformaRequired, new { disabled = "disabled" })
                @Resources_frank.PurchaseOrder_String_ProformaInvoice
            </td>
            <td width="25%">
                @Html.CheckBoxFor(p => p.POEntiy.CommercialInvoiceRequired, new { disabled = "disabled" })
                @Resources_frank.PurchaseOrder_String_CommercialInvoice
            </td>
            <td width="25%">
                @Html.CheckBoxFor(p => p.POEntiy.WayBillRequired, new { disabled = "disabled" })
                @Resources_frank.PurchaseOrder_String_WaybillAirbill
            </td>
            <td width="25%">
                &nbsp;@Html.CheckBoxFor(p => p.POEntiy.PackingListRequired, new { disabled = "disabled" })
                @Resources_frank.PurchaseOrder_String_PackingList
            </td>
        </tr>
        <tr>
            <td width="25%">
                @Html.CheckBoxFor(p => p.POEntiy.DeliveryNoteRequired, new { disabled = "disabled" })
                @Resources_frank.PurchaseOrder_String_DeliveryNote
            </td>
            <td width="25%">
                @Html.CheckBoxFor(p => p.POEntiy.ManualsRequired, new { disabled = "disabled" })
                @Resources_frank.PurchaseOrder_LoadOtherPODetails_Manuals
            </td>
            <td width="25%">
                @Html.CheckBoxFor(p => p.POEntiy.CertificatesReqired, new { disabled = "disabled" })
                @Resources_frank.PurchaseOrder_LoadOtherPODetails_Certificates
            </td>
            <td width="25%">
                <table>
                    <tr>
                        <td style="border-color: White;">@Html.CheckBoxFor(p => p.POEntiy.OtherRequired, new { disabled = "disabled" })
                        </td>
                        <td style="border-color: White;">@Model.POEntiy.OtherSpecify
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <th>
                @Resources_frank.PurchaseOrder_LoadOtherPODetails_ShippingMarks
            </th>
            <th>
                @Resources_frank.PurchaseOrder_LoadOtherPODetails_ConsigneeAddress
            </th>
            <th>
                @Resources_frank.Global_String_EmailAddress 1
            </th>
            <th>
                @Resources_frank.Global_String_EmailAddress 2
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.POEntiy.ShippingMarks
                &nbsp;
            </td>
            <td align="center">
                @Model.POEntiy.ConsigneeAddress
            </td>
            <td id="csEmail1" align="center">
                @Model.POEntiy.ConsigneeEmail1
            </td>
            <td id="csEmail2" align="center">
                @Model.POEntiy.ConsigneeEmail2
            </td>
        </tr>
        <tr>
            <th>
                @Resources_frank.PurchaseOrder_LoadOtherPODetails_PreFinancing
            </th>
            <th>
            </th>
            <th>
            </th>
            <th>
            </th>
        </tr>
        <tr>
            <td align="center">
                <table border="0">
                    <tr>
                        <td style="border-color: White;">@Html.CheckBoxFor(p => p.POEntiy.PrefinancingGuaranteeRequired, new { disabled = "disabled" })
                        </td>
                        <td style="border-color: White;">
                            @if (Model.POEntiy.PFGPercentage != null)
                            {
                                @Model.POEntiy.PFGPercentage.Value.ToString("#,##0.00")
                                @Html.Raw(" %")
                            }
                        </td>
                    </tr>
                </table>
            </td>
            <td>
            </td>
            <td>
            </td>
            <td>
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <td width="19%">
                @Resources_frank.Approver_ApproverList_Authorization
            </td>
            <td width="27%">
               @Resources_frank.Global_String_RequesterOrUnit
            </td>
            <td width="27%">
                @Resources_frank.ExpenseClaim_ViewExpsClaimsDetails_FinanceReview
            </td>
            <td width="27%">
                @Resources_frank.ExpenseClaim_ViewExpsClaimsDetails_ECFAuthorizedBy
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources_frank.Global_String_Name:
            </td>
            <td>
                @Model.StaffEntity.Person.FirstName &nbsp; @Model.StaffEntity.Person.OtherNames
            </td>
            <td>
                @if (Model.ReviewdBy != null)
                {
                    @Model.ReviewdBy.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.ReviewdBy.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null)
                {
                    @Model.AuthorizdBy.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.AuthorizdBy.Person.OtherNames
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources_frank.Global_String_Title:
            </td>
            <td>
                @Model.StaffEntity.Designation.Name
            </td>
            <td>
                @if (Model.ReviewdBy != null)
                {
                    @Model.ReviewdBy.Designation.Name
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null)
                {
                    @Model.AuthorizdBy.Designation.Name
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources_frank.Global_String_Date:
            </td>
            <td>
                @Model.POEntiy.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td>
                @if (Model.ReviewdBy != null)
                {
                    @Model.ReveiwDate.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null)
                {
                    @Model.AuthorizDate.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources_frank.Global_String_Signature:
            </td>
            <td>
                @if (Model.StaffEntity.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.StaffEntity.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.ReviewdBy != null && Model.ReviewdBy.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.ReviewdBy.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null && Model.AuthorizdBy.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.AuthorizdBy.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
        </tr>
    </table>
    <hr />
    @if (Model.POEntiy.IsAuthorized == true)
    {
        <a class="btn btn-primary"  href="@Url.Action("Index", "PO", new { area = "Reports", POid = Model.POId })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
            @Resources_frank.Budget_ViewBudget_DownloadPdf</a>
        <br />
    }
</div>
<p>
    @Ajax.ActionLink(Resources_frank.Global_String_BackToList, "Index", new { id = "ViewPurchaseOrders" }, new AjaxOptions
    {
        UpdateTargetId = "PODiv",
        LoadingElementId = "loading",
        Url = Url.Action("ViewPurchaseOrders"),
        OnSuccess = "initSorter();sorter.size(50);"
    })
</p>
